filelist=$(readlink -f $1)

#RunNumuCCAnalysis.exe
exe=$2

id=$3

echo filelist $filelist
echo exe $exe
echo id $id


###############################################

dir0=job$id

mkdir -p $dir0

echo inputing...

nf=$(wc $filelist | awk '{print $1}')
echo nf $nf
#test
#nf=3

####################################################

cd $dir0

echo $filelist  > inlog

for ii in $(seq -w 1 $nf)
do
    ff=$(head -n $ii $filelist | tail -n 1)
    jobfile=$id\n$ii.sh

    cat > $jobfile <<EOF
source $(readlink -f ~/t2ksoft.sh)

cd $(pwd)

date

$exe -o AnaOut_sub$ii\.root $ff

date

EOF

    chmod +x $jobfile


   qsub -l cput=00:10:00 -N $jobfile  ./$jobfile 

   nq=$(qstat | grep $(whoami) | grep Q |wc | awk '{print $1}' )
   while [ $nq -gt 10 ]
   do
       sleep 10
       nq=$(qstat | grep $(whoami) | grep Q |wc | awk '{print $1}' )
   done

    ii=$( expr $ii + 1 )

done



echo done $ii

